#pragma once
#include "InOut.h"
#include "ChessStatus.h"
#include <IPolicy.h>

class WinnerChecker;
class ChessStatus;

class FutureStep : public ExperientialSystem::IPolicy
{
	WinnerChecker* _winnerChecker;

	const int UPDATE_DEPTH = 3;
	const double WIN_VALUE = 1;
	const double LOSE_VALUE = 0;

public:
	FutureStep(WinnerChecker* winnerChecker);
	~FutureStep();

	virtual void Update(ExperientialSystem::IStatus* status);

private:

	void InternalUpdate(vector<ChessStatus*>& statusChain, int Depth);

	bool BlackWin(const ChessStatus::Color togo, ChessStatus* status) const;
	bool WhiteWin(const ChessStatus::Color togo, ChessStatus* status) const;

	//Update in the chain the win rate from previous status to the next status.
	//The <winRate> indicates the win rate of the status after the last one of the <statusChain>.
	void UpdateStatusChain(vector<ChessStatus*>& statusChain, double winRate);
};

class WinnerChecker
{
public:
	enum Winner
	{
		Black,
		White,
		None
	};

	virtual WinnerChecker::Winner Check(ChessStatus* status) const = 0;
};

